<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<!--公共JS开始-->
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.timer.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<!--公共JS结束-->
<!--数据列表插件开始-->
<link href="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.ui.position.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.js"></script>
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Css/etgrid.css">
<script src="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Js/etgrid.js"></script>
<!--数据列表插件结束-->
<style type="text/css">
	body {
		overflow:hidden;
	}
	.table_box {
	}
</style>
</head>

<body>
	<div class="page_header">
	<div class="table_tool">
		<ul class="clearfix">			
			<li class="memberDel btn"><i class="icon-remove"></i> 批量删除</li>
			<li class="line"></li>
			<li class="openwin btn" etitle="新增饮品" eheight="500px" ewidth="800px" ehref="{:U('Restaurant/drinkAdd')}" id="Restaurant_drinkAdd"><i class="icon-plus"></i> 新增饮品</li>
		</ul>
	</div>
	<div class="search_box">
		所属地区：<div id="areaBox"></div>
		类型：
		<select name="type" id="type" class="form_ele w100">
			<option value="">请选择</option>
			<option value="1">加盟店</option>
			<option value="2">直营店</option>
		</select>
		星级：
		<select name="level" id="level" class="form_ele w100">
			<option value="">请选择</option>
			<option value="1">一星级</option>
			<option value="2">二星级</option>
			<option value="3">三星级</option>
			<option value="4">四星级</option>
			<option value="5">五星级</option>
		</select>
		菜系：
		<select name="cuisine" id="cuisine" class="form_ele w100">
			<option value="">请选择</option>
			<volist name="cuisine" id="v">
				<option value="{$key}">{$v[0]}</option>
			</volist>
		</select>
		关键字：<input type="text" id="keywords" class="form_ele w100">
		<span id="doSearch" class="doSearch">
			<i class="icon-search"></i> 搜索
		</span>
		<span id="doRest" class="doSearch">重置搜索条件</span>
	</div>
	
	</div>
	<div class="table_box">
	</div>
</body>
<script type="text/javascript">
	var listConfig = {
			gridId : 'memberList',
			blockBox : '.table_box',
			blockBoxHeight : 'window',
			jsonUrl : '__URL__/index',
			where : '',
	 		getWhere : function(){
	 			var where         = {};
				where['type']     = $('#type').val();
				where['level']    = $('#level').val();
				where['cuisine']  = $('#cuisine').val();
				where['keywords'] = $('#keywords').val();
				where['area2']    = $('.selected2').val();
				where['area3']    = $('.selected3').val();
				where['area4']    = $('.selected4').val();
				return where;
			},
			
			widthType : 'tdw', //thw-标题标准宽度、tdw-数据单元标准宽度、auto-随数据单元宽度
			pageNum : 10,
			nowPage : 1,
			orderName : "addtime",
			orderDirection : "desc",
			dataContextMenuOpen: true, //是否开启数据行右键菜单
			dataContextMenu: function(){
				$.contextMenu({
					selector: '.et_tbody tr',
					items: {
						"edit": {
							name: "修改", 
							icon: "edit",
							callback: function(key, options) {
								var href   = "{:U('Restaurant/edit')}&id="+$(this).attr('rowid');
								var width  = '800px';
								var height = '500px';
								var title  = '修改餐厅';
								openDialog('Restaurant_edit',href,width,height,title);
							}
						},
						"delete": {
							name: "删除", 
							icon: "edit",
							callback: function(key, options) {
								//var title =  $(this).children('td[fieldname="title"]').html();
								
								var id = $(this).attr('rowid');
								$.post("{:U('Restaurant/del')}",{val:id},function(data){
									$('.et_tfoot .page_refresh').click(); //刷新加载
								})
							}
						}
					}
				});
			},
			colModel : [
				{
					display : 'checkbox',
					name : 'id',
					sortable : false,
					myclass : 'center',
					edit : false
				},
				{
					display : '名称',
					name : 'title',
					sortable : true,
					myclass : 'center',
					edit : true
				},
				{
					display : '城市',
					name : 'city',
					sortable : true,
					myclass : 'center',
					edit : true
				},
				{
					display : '类型',
					name : 'type',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'60px'
				},
				{
					display : '星级',
					name : 'level',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'50px',
				},
				{
					display : '电话',
					name : 'tel',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '电邮',
					name : 'email',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '添加时间',
					name : 'addtime',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'95px'
				},
			]
		};
	
	//实例化列表
	var tableList = $('.table_box').EtGrid(listConfig);
	//tableList.erefresh();
	
	//搜索
 	$('#doSearch').on('click',function(){
		
		var where = tableList.config.getWhere();
		
		tableList.config.where = where;
		tableList.search();
	});
	
	//重置搜索条件
	$('#doRest').on('click',function(){
		$('#type').val('');
		$('#cuisine').val('');
		$('#level').val('');
		$('#keywords').val('');
		$('#area2').val('');

		$('.selected2').val('');
		$('.selected3').remove();
		$('.selected4').remove();
	})
	
	//批量删除
	$('.memberDel').on('click',function(){
		
		var val = tableList.getChecked();
		var msg = "确认要将选中的餐厅删除吗？";
		
		if(val){
			windowApi.lhgdialog.confirm(msg, function(){
				$.post("{:U('Restaurant/del')}",{val:val},function(data){
					if(data.status==1){
						$('.et_tfoot .page_refresh').click(); //刷新加载
					}else{
						windowApi.lhgdialog.alert(data.info,function(){return;});
					}
				});
			},function(){
				return;
			});
		}else{
			windowApi.lhgdialog.alert('请选择需要删除的会员！');
		}
	});
	

	var linkage_json   = {$json|json_encode} ;
	$(function(){
		//初始值处理
		var did = '';
		if(did!=''){
			$('#areaBox').html(dealInitialarea(did,'',1));
		}else{
			$('#areaBox').html(showLinkagearea(39,2,0));
		}
		$('select[name="area"]').live('change',function(){
			var nowLevel  = parseInt($(this).attr('level'));
			var nextLevel = nowLevel+1;
			var enhtml    = '';
			
			//清除自此以后的select
			$('select[name="area"]').each(function(index, element) {
				if(parseInt($(this).attr('level'))>nowLevel){
					$(this).remove();
				}
			});
			
			$('#ssxadd').val($('select[name="area"]').find("option:selected").text());
			
			$('input[name="area'+nowLevel+'"]').val($(this).val());
			//显示下一个select
			$('#areaBox').append(showLinkagearea($(this).val(),nextLevel,0));
		});
		
		//处理初始值
		function dealInitialarea(lid,result,level){
			if(lid){
				$.each(linkage_json , function(i, n){
					if(lid==i){
						result = dealInitialarea(n[1],result,(parseInt(level)-1))+''+showLinkagearea(n[1],level,i);
						return false;
					}
				});
			}
			return result;
		}
		
		//响应select改变事件
		function showLinkagearea(pid,level,nid){
			var html = ''; //最终输出的HTML
			var have = false; //是否有子词典
			html += '<select name="area" id="area'+level+'" level="'+level+'" class="form_ele w100 selected'+level+'">';
			html += '<option value="0">请选择</option>';
			$.each(linkage_json , function(i, n){
				if(pid==n[1]){
					if(nid==i){
						html += '<option value="'+i+'" selected>'+n[0]+'</option>';
					}else{
						html += '<option value="'+i+'">'+n[0]+'</option>';
					}
					have = true;
				}
			});
			html += '</select>';
			html += '<input type="hidden" name="area'+level+'" id="area'+level+'"/>';
			
			//没有子词典则此次输出为空
			if(!have){
				html = '';
			}
			
			return html;
		}
	});	
	
	
</script>
</html>
